<template>
	<div id="app">
		<div id="release">
			<div class="cover">
				<div title="" class="title">
					<img id="isgod" src="https://yo.docshare.org.cn/static/images/write.png" />
					<input type="text" class="input" v-model="fd.articletitle" placeholder="为你的游记题名" />
					<div class="clear"></div>
				</div>
			</div>
			<div class="fill">
				<div class="am-form-group">
					<textarea class="text" rows="5" id="doc-ta-1" v-model="fd.articlecontent"
						placeholder="说说这次旅行"></textarea>
				</div>
			</div>
			<div style="display: flex;justify-content: center;align-items: center;">
				<div>
					
				<button @click="choseFile">选择你的游记背景图片</button>
				<image style="width: 100px;height: 100px;" :src="fd.background.path"></image>
				</div>
				<div>
				<button @click="choseFile1">选择你的游记内容图片</button>
				<image style="width: 100px;height: 100px;" :src="fd.contentphoto.path"></image>
				</div>
			</div>
			<div>
				<input type="submit" class="keep" @click="savebox()" value="保存"></input>
				<input type="submit" @click="postword()" class="done" value="发布"> </input>
			</div>
		</div>
	</div>
</template>

<script>
	import config from '@/config'
	export default {
		data() {
			return {
				usr: '',
				uni,
				release: {},
				file1: '',
				file2: '',
				fd: {
					// shuru:"",
					articletitle: "",
					articlecontent: "",
					articledate: "",
					background: "",
					contentphoto: ""
				},
			}
		},
		methods: {
			choseFile() {
				var that = this;
				// #ifdef MP-WEIXIN
				wx.chooseMessageFile({
					count: 1,
					type: 'image',
					success(res) {
						debugger
						that.fd.background = res.tempFiles[0]
					}
				})
				// #endif
				// #ifdef H5
				uni.chooseFile({
					count: 1,
					type: 'image',
					success(res) {
						that.fd.background = res.tempFiles[0]
					}
				})
				// #endif
			},
			choseFile1() {
				var that = this;
				// #ifdef MP-WEIXIN
				wx.chooseMessageFile({
					count: 1,
					type: 'image',
					success(res) {
						debugger
						that.fd.contentphoto = res.tempFiles[0]
					}
				})
				// #endif
				// #ifdef H5
				uni.chooseFile({
					count: 1,
					type: 'image',
					success(res) {
						that.fd.contentphoto = res.tempFiles[0]
					}
				})
				// #endif
			},
			chooseSuccessHandle(tempFilePaths, type) {
				var that = this;
				uni.request({
					url: tempFilePaths[0],
					success(res) {
						var fileCode = res.data;
						that.fd.background = fileCode;

					}
				})
			},
			chooseSuccessHandle1(tempFilePaths, type) {
				var that = this;
				uni.request({
					url: tempFilePaths[0],
					success(res) {
						var fileCode = res.data;
						that.fd.contentphoto = fileCode;
					}
				})
			},
			getFIle1(fileField) {
				var files = fileField.tempFiles;
				this.file1 = files[0];
			},
			getFIle2(fileField) {
				var files = fileField.tempFiles;
				this.file2 = files[0];
			},
			postword: function() {
				let config1 = {
					headers: {}
				}
				uni.request({
					url: `${config.baseUrl}/article/post?token=${uni.getStorageSync('token')}`,
					method: 'POST',
					data: this.fd,
					header: config1.headers,
					success(r) {
						if (r.data.succ) {
							uni.navigateTo({
								url: 'beautiful_list'
							})
						} else {
							console.log(r.data);
							// alert(r.data.msg);
						}
					},
					complete(res) {
						if (res.data && res.data.msg) {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							})
						}
					},
				})
			},
			savebox: function() {
				let config1 = {
					headers: {
						// 'Content-Type': 'multipart/form-data'
					}
				}
				uni.request({
					url: `${config.baseUrl}/article/savebox?token=${uni.getStorageSync('token')}`,
					method: 'POST',
					data: this.fd,
					header: config1.headers,
					success(r) {
						if (r.data.succ) {
							uni.navigateTo({
								url: 'beautiful_list'
							})
						} else {
							console.log(r.data);
							// alert(r.data.msg);
						}
					},
					complete(res) {
						if (res.data && res.data.msg) {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							})
						}
					},
				})
			},
		},
	}
</script>

<style scoped>
	.input {
		width: 80%;
		height: 40px;
		font-size: 20px;
		line-height: 30px;
		outline: none;
		color: #666356;
		outline-style: none;
		border-radius: 15px;
		border: 2px solid #ccc;
		padding: 7px 7px;
		background-color: #d0d3bf;
	}

	textarea {
		outline: none;
	}

	.file {
		position: relative;
		display: inline-block;
		background: #D0EEFF;
		border: 1px solid #99D3F5;
		border-radius: 4px;
		padding: 4px 12px;
		overflow: hidden;
		color: #1E88C7;
		text-decoration: none;
		text-indent: 0;
		line-height: 20px;
	}

	.file input {
		position: absolute;
		font-size: 100px;
		right: 0;
		top: 0;
		opacity: 0;
	}

	.file:hover {
		background: #AADFFD;
		border-color: #78C3F3;
		color: #004974;
		text-decoration: none;
	}
</style>
